<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增项目文件')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-file-add">
        <input name="id" th:field="${sysProjectFile.id}"
               type="hidden">
        <input name="projectId" th:field="${sysProject.projectId}"
               type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">所属项目：</label>
            <div class="col-sm-8">
                <input name="projectName" th:field="${sysProject.projectName}"
                       class="form-control" type="text" readonly="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">文件类型：</label>
            <div class="col-sm-8">
                <input name="fileType" th:field="${sysProjectFile.fileType}"
                       class="form-control" type="text" readonly="true">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">文件名称：</label>
            <div class="col-sm-8">
                <input name="fileName" th:field="${sysProjectFile.fileName}"
                       class="form-control" type="text" readonly="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否上传完：</label>
            <div class="col-sm-8">
                <label class="radio-box"> <input type="radio" name="status" value="1"/> 已完成 </label>
                <label class="radio-box"> <input type="radio" name="status" value="0"/> 未完成 </label>
            </div>
        </div>
        <div class="form-group" id="expirationTimeId">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>过期时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input type="text" class="form-control" name="expirationTime">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">项目附件：</label>
            <div class="col-sm-8">
                <input id="fileinput-project" class="form-control"
                       name="attachment" type="file" multiple>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "process/projectfile"
    var type_prefix = ctx + "process/projectfiletype"

    var sysProjectFile = [[${sysProjectFile}]];

    $("#form-file-add").validate({
        focusCleanup: true
    });

    $(".input-group.date").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $('#fileinput-project').fileinput('upload');
        }
    }

    $("input[name='crtTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='updTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function () {
        //附件上传相关
        $("#fileinput-project").fileinput({
            theme: 'explorer-fas',
            uploadUrl: prefix + "/add",
            enctype: 'multipart/form-data',
            showUpload: false,
            uploadAsync: false,
            showPreview: false,
            showCancel: true,
            dropZoneEnabled: false,
            layoutTemplates: {
                actionUpload: '',//去除上传预览缩略图中的上传图片
                actionDelete: '', //去除上传预览的缩略图中的删除图标
            },
            initialPreviewAsData: true,
            uploadExtraData: function () {
                var fields = $('#form-file-add').serializeArray();
                var data = {};
                $.each(fields, function (index, field) {
                    data[field.name] = field.value;
                })
                return data;
            }
        }).on('filebatchuploadsuccess',
            function (event, data, previewId, index) {
                $.modal.close();
                $.operate.successCallback(data.response);
            });

        if (sysProjectFile.fileTypeName == "临时建设") {
            $("#expirationTimeId").attr("style", "display:block;")
        } else {
            $("#expirationTimeId").attr("style", "display:none;")
        }

    });
</script>
</body>
</html>